//
//  PKDetailViewController.m
//  ShrimpCrowdordering
//
//  Created by 郑洲 on 2018/7/30.
//  Copyright © 2018年 郑洲. All rights reserved.
//

#import "PKDetailViewController.h"
#import "ShareView.h"
#import "UIImage+GradientColor.h"

#import <TencentOpenAPI/QQApiInterface.h>
#import <TencentOpenAPI/TencentOAuth.h>
#import "WeiboSDK.h"
#import "WXApi.h"

@interface PKDetailViewController ()<UITextViewDelegate, TencentSessionDelegate>

@property (nonatomic, strong) UIScrollView *scrollView;

@property (nonatomic,assign) NSInteger time;
@property (nonatomic,strong) NSTimer *timer;//计时器
@property (nonatomic,strong) UILabel *timeLabel;

@property (nonatomic,strong) UIView *shadowView;
@property (nonatomic,strong) UIView *resultView;
@property (nonatomic, strong) UIButton *shadowBtn;
@property (nonatomic,strong) ShareView *shareView;
@property (nonatomic, copy) NSString *proId;
@property (nonatomic, copy) NSString *shareId;
@property (nonatomic, copy) NSString *shareName;
@property (nonatomic, copy) NSString *shareLink;

@property (nonatomic, strong) TencentOAuth *tencentOAuth;

@end

@implementation PKDetailViewController

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self.timer invalidate];
    self.timer = nil;
    [self.resultView removeFromSuperview];
    [self.shareView removeFromSuperview];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"PK";
    self.view.backgroundColor = TABLEVIEW_BACKGROUNDCOLOR;
    
    [self setRightButton:ImageWithName(@"分享") title:nil target:self action:@selector(showShareView)];
    
    _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - NAVIGATION_BAR_HEIGHT)];
    _scrollView.contentSize = CGSizeMake(0, ScreenX375(738));
    _scrollView.showsVerticalScrollIndicator = NO;
    _scrollView.showsHorizontalScrollIndicator = NO;
    [self.view addSubview:_scrollView];
    
    [self getData];
}

- (void)getData {
    [HttpManager postHttpRequestByGet:[NSString stringWithFormat:@"%@api/getPkInfo",REQUESTHEADER] andParameter:@{@"id":_pkId} success:^(id successResponse) {
        NSString *status = [NSString stringWithFormat:@"%@",successResponse[@"code"]];
        if ([status isEqualToString:@"200"]) {
            NSError *error = nil;
            PKDetailModel *model = [[PKDetailModel alloc] initWithDictionary:successResponse[@"data"][@"data"] error:&error];
            self.model = model;
            [self setTopUI];
            
            NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
            [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
            //然后创建日期对象
            NSDate *date1 = [dateFormatter dateFromString:[HttpManager TimeStamp:self.model.endTime]];
            NSDate *date = [NSDate date];
            //计算时间间隔（单位是秒）
            NSTimeInterval time = [date1 timeIntervalSinceDate:date];
            self.time = time;
            if (time > 0) {
                [self setBottomUI];
            }
        }else {
            [HttpManager showNoteMsg:[NSString stringWithFormat:@"%@",successResponse[@"msg"]]];
        }
    } andFailure:^(id failureResponse) {
        [HttpManager showFail];
    }];
}

- (void)getResult {
    [HttpManager postHttpRequestByGet:[NSString stringWithFormat:@"%@api/getPkInfo",REQUESTHEADER] andParameter:@{@"id":_pkId} success:^(id successResponse) {
        NSString *status = [NSString stringWithFormat:@"%@",successResponse[@"code"]];
        if ([status isEqualToString:@"200"]) {
            NSError *error = nil;
            PKDetailModel *model = [[PKDetailModel alloc] initWithDictionary:successResponse[@"data"][@"data"] error:&error];
            self.model = model;
            
            self.resultView = [[UIView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH - ScreenX375(300)) / 2, ScreenX375(70), ScreenX375(300), ScreenX375(380))];
            self.resultView.backgroundColor = [UIColor whiteColor];
            self.resultView.layer.cornerRadius = ScreenX375(6);
            [kKeyWindow addSubview:self.resultView];
            
            UIImageView *bgView = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(40), ScreenX375(34), ScreenX375(206), ScreenX375(199))];
            bgView.userInteractionEnabled = YES;
            [self.resultView addSubview:bgView];
            
            UIButton *closeBtn = [[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(271), 0, ScreenX375(29), ScreenX375(29))];
            [closeBtn setImage:ImageWithName(@"关闭") forState:UIControlStateNormal];
            [closeBtn addTarget:self action:@selector(close) forControlEvents:UIControlEventTouchUpInside];
            [self.resultView addSubview:closeBtn];
            
            UILabel *noteLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, ScreenX375(238), ScreenX375(300), ScreenX375(19))];
            noteLabel.textColor = REXADECIMALCOLOR(@"#f2223b");
            noteLabel.font = Kfont(15);
            noteLabel.textAlignment = NSTextAlignmentCenter;
            [self.resultView addSubview:noteLabel];
            
            if ([model.winId isEqualToString:kNSUDefaultReadKey(@"userId")]) {
                bgView.image = ImageWithName(@"我赢啦");
                noteLabel.text = [NSString stringWithFormat:@"以%@个赞赢对方！",model.initiatZan];
                
                UIImageView *bgImg = [[UIImageView alloc] initWithFrame:CGRectMake(0, -ScreenX375(70), ScreenX375(300), ScreenX375(450))];
                bgImg.userInteractionEnabled = YES;
                bgImg.image = ImageWithName(@"光");
                [self.resultView insertSubview:bgImg atIndex:0];
            }else {
                bgView.image = ImageWithName(@"我输啦");
                self.resultView.clipsToBounds = YES;
                noteLabel.text = [NSString stringWithFormat:@"以%@个赞输给对方！",model.initiatZan];
            }
            
            UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(ScreenX375(20), ScreenX375(265), ScreenX375(260), ScreenX375(47))];
            textView.textColor = REXADECIMALCOLOR(@"#888888");
            textView.text = @"给对方留个言";
            textView.font = Kfont(15);
            textView.layer.cornerRadius = ScreenX375(6);
            textView.clipsToBounds = YES;
            textView.returnKeyType = UIReturnKeyDone;
            textView.textAlignment = NSTextAlignmentCenter;
            textView.backgroundColor = REXADECIMALCOLOR(@"#f4f4f4");
            textView.delegate = self;
            [self.resultView addSubview:textView];
            
            UIButton *sendBtn = [[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(100), ScreenX375(326), ScreenX375(100), ScreenX375(34))];
            [sendBtn setTitle:@"发送" forState:UIControlStateNormal];
            [sendBtn setTitleColor:REXADECIMALCOLOR(@"#ffffff") forState:UIControlStateNormal];
            sendBtn.titleLabel.font = Kfont(14);
            [sendBtn setBackgroundImage:ImageWithName(@"按钮背景") forState:UIControlStateNormal];
            sendBtn.layer.cornerRadius = ScreenX375(17);
            sendBtn.layer.masksToBounds = YES;
            [self.resultView addSubview:sendBtn];
            
        }else {
            [HttpManager showNoteMsg:[NSString stringWithFormat:@"%@",successResponse[@"msg"]]];
        }
    } andFailure:^(id failureResponse) {
        [HttpManager showFail];
    }];
}

- (void)setTopUI {
    UIImageView *otherView = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(37), ScreenX375(385), SCREEN_WIDTH - ScreenX375(74), ScreenX375(300))];
    [otherView sd_setImageWithURL:[NSURL URLWithString:_model.acceptProPic] placeholderImage:nil options:SDWebImageRetryFailed];
    otherView.layer.cornerRadius = ScreenX375(6);
    otherView.clipsToBounds = YES;
    otherView.contentMode = UIViewContentModeScaleAspectFill;
    [self.scrollView addSubview:otherView];
    
    CGFloat otherNameWidth = kGetStringWidth(_model.acceptorName, CGSizeMake(ScreenX375(150), ScreenX375(16)), KBlodfont(14));
    UIView *otherDetail = [[UIView alloc] initWithFrame:CGRectMake(ScreenX375(14), ScreenX375(14), ScreenX375(72) + otherNameWidth, ScreenX375(36))];
    otherDetail.layer.cornerRadius = ScreenX375(18);
    otherDetail.layer.shadowOffset = CGSizeMake(0, 2); //设置阴影的偏移量
    otherDetail.layer.shadowRadius = ScreenX375(8);  //设置阴影的半径
    otherDetail.layer.shadowColor = RGBACOLOR(0, 0, 0, 0.09).CGColor; //设置阴影的颜色为黑色
    otherDetail.layer.shadowOpacity = 1; //设置阴影的不透明度
    otherDetail.backgroundColor = [UIColor whiteColor];
    [otherView addSubview:otherDetail];
    
    UIImageView *otherHead = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(12), ScreenX375(4), ScreenX375(28), ScreenX375(28))];
    otherHead.layer.cornerRadius = ScreenX375(14);
    otherHead.clipsToBounds = YES;
    [otherHead sd_setImageWithURL:[NSURL URLWithString:_model.acceptorPic] placeholderImage:nil options:SDWebImageRetryFailed];
    [otherDetail addSubview:otherHead];
    
    UILabel *otherName = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(50), ScreenX375(10), otherNameWidth + ScreenX375(2), ScreenX375(16))];
    otherName.text = _model.acceptorName;
    otherName.textColor = REXADECIMALCOLOR(@"#f21934");
    otherName.font = KBlodfont(14);
    [otherDetail addSubview:otherName];
    
    UIImageView *myImage = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(37), ScreenX375(20), SCREEN_WIDTH - ScreenX375(74), ScreenX375(300))];
    myImage.layer.cornerRadius = ScreenX375(8);
    myImage.clipsToBounds = YES;
    myImage.contentMode = UIViewContentModeScaleAspectFill;
    [myImage sd_setImageWithURL:[NSURL URLWithString:_model.initiatProPic] placeholderImage:nil options:SDWebImageRetryFailed];
    [self.scrollView addSubview:myImage];
    
    CGFloat myNameWidth = kGetStringWidth(kNSUDefaultReadKey(@"nickName"), CGSizeMake(ScreenX375(150), ScreenX375(16)), KBlodfont(14));
    UIView *myDetail = [[UIView alloc] initWithFrame:CGRectMake(ScreenX375(14), ScreenX375(14), ScreenX375(72) + myNameWidth, ScreenX375(36))];
    myDetail.layer.cornerRadius = ScreenX375(18);
    myDetail.layer.shadowOffset = CGSizeMake(0, 2); //设置阴影的偏移量
    myDetail.layer.shadowRadius = ScreenX375(8);  //设置阴影的半径
    myDetail.layer.shadowColor = RGBACOLOR(0, 0, 0, 0.09).CGColor; //设置阴影的颜色为黑色
    myDetail.layer.shadowOpacity = 1; //设置阴影的不透明度
    myDetail.backgroundColor = [UIColor whiteColor];
    [myImage addSubview:myDetail];
    
    UIImageView *myHead = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(12), ScreenX375(4), ScreenX375(28), ScreenX375(28))];
    myHead.layer.cornerRadius = ScreenX375(14);
    myHead.clipsToBounds = YES;
    [myHead sd_setImageWithURL:[NSURL URLWithString:kNSUDefaultReadKey(@"pic")] placeholderImage:nil options:SDWebImageRetryFailed];
    [myDetail addSubview:myHead];
    
    UILabel *myName = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(50), ScreenX375(10), myNameWidth + ScreenX375(2), ScreenX375(16))];
    myName.text = kNSUDefaultReadKey(@"nickName");
    myName.textColor = REXADECIMALCOLOR(@"#4a90e2");
    myName.font = KBlodfont(14);
    [myDetail addSubview:myName];
}

- (void)setBottomUI {
    self.shadowView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, ScreenX375(738))];
    self.shadowView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
    [self.scrollView addSubview:self.shadowView];
    
    UILabel *noteLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(16), ScreenX375(270), SCREEN_WIDTH - ScreenX375(48), ScreenX375(22))];
    noteLabel.text = @"PK进度条";
    noteLabel.font = KBlodfont(16);
    noteLabel.textColor = REXADECIMALCOLOR(@"#ffffff");
    [self.shadowView addSubview:noteLabel];
    
    UIButton *myPraise = [[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(16), ScreenX375(315), ScreenX375(60), ScreenX375(15))];
    [myPraise setImage:ImageWithName(@"Combined Shape Copy") forState:UIControlStateNormal];
    [myPraise setTitle:[NSString stringWithFormat:@"  %@",_model.initiatZan] forState:UIControlStateNormal];
    [myPraise setTitleColor:REXADECIMALCOLOR(@"#ffffff") forState:UIControlStateNormal];
    myPraise.titleLabel.font = Kfont(13);
    myPraise.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [self.shadowView addSubview:myPraise];
    
    UIImageView *myHead = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(70), ScreenX375(316), ScreenX375(14), ScreenX375(14))];
    myHead.layer.cornerRadius = ScreenX375(7);
    myHead.clipsToBounds = YES;
    [myHead sd_setImageWithURL:[NSURL URLWithString:kNSUDefaultReadKey(@"pic")] placeholderImage:nil options:SDWebImageRetryFailed];
    [self.shadowView addSubview:myHead];
    
    UILabel *myName = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(88), ScreenX375(316), ScreenX375(70), ScreenX375(15))];
    myName.text = kNSUDefaultReadKey(@"nickName");
    myName.textColor = REXADECIMALCOLOR(@"#4a90e2");
    myName.font = KBlodfont(13);
    [self.shadowView addSubview:myName];
    
    CGFloat otherNameWidth = kGetStringWidth(_model.acceptorName, CGSizeMake(ScreenX375(150), ScreenX375(16)), KBlodfont(13));
    UIImageView *otherHead = [[UIImageView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - otherNameWidth - ScreenX375(90), ScreenX375(316), ScreenX375(14), ScreenX375(14))];
    otherHead.layer.cornerRadius = ScreenX375(7);
    otherHead.clipsToBounds = YES;
    [otherHead sd_setImageWithURL:[NSURL URLWithString:_model.acceptorPic] placeholderImage:nil options:SDWebImageRetryFailed];
    [self.shadowView addSubview:otherHead];
    
    UILabel *otherName = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - otherNameWidth - ScreenX375(70), ScreenX375(316), otherNameWidth + ScreenX375(2), ScreenX375(15))];
    otherName.text = _model.acceptorName;
    otherName.textColor = REXADECIMALCOLOR(@"#f21934");
    otherName.font = KBlodfont(13);
    [self.shadowView addSubview:otherName];
    
    UIButton *otherPraise = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - ScreenX375(76), ScreenX375(315), ScreenX375(60), ScreenX375(15))];
    [otherPraise setImage:ImageWithName(@"Combined Shape") forState:UIControlStateNormal];
    [otherPraise setTitle:[NSString stringWithFormat:@"%@",_model.acceptZan] forState:UIControlStateNormal];
    [otherPraise setTitleColor:REXADECIMALCOLOR(@"#ffffff") forState:UIControlStateNormal];
    otherPraise.titleLabel.font = Kfont(13);
    otherPraise.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    [otherPraise setTitleEdgeInsets:UIEdgeInsetsMake(0, -WIDTH(otherPraise.imageView), 0, WIDTH(otherPraise.imageView))];
    [otherPraise setImageEdgeInsets:UIEdgeInsetsMake(0, WIDTH(otherPraise.titleLabel), 0, -WIDTH(otherPraise.titleLabel))];
    [self.shadowView addSubview:otherPraise];
    
    UIProgressView *pro = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
    pro.frame = CGRectMake(ScreenX375(16), ScreenX375(345), SCREEN_WIDTH - ScreenX375(32), ScreenX375(8));
    pro.trackTintColor = REXADECIMALCOLOR(@"#f21934");
    pro.progressTintColor = REXADECIMALCOLOR(@"#34a7ff");
    if ([_model.initiatZan integerValue] + [_model.acceptZan integerValue] > 0) {
        pro.progress = [_model.initiatZan floatValue] / ([_model.initiatZan integerValue] + [_model.acceptZan integerValue]);
    }else {
        pro.progress = 0.5;
    }
    pro.transform = CGAffineTransformMakeScale(1.0f, 7.0f);
    [self.shadowView addSubview:pro];
    for (UIImageView * imageview in pro.subviews) {
        imageview.layer.cornerRadius = 10;
        imageview.clipsToBounds = YES;
    }
    
    UIImage *bgImg = [UIImage gradientColorImageFromColors:@[REXADECIMALCOLOR(@"#ff1162"),REXADECIMALCOLOR(@"#fe4e4e")] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(ScreenX375(100), ScreenX375(100))];
    UIImageView *timeView = [[UIImageView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH - ScreenX375(100)) / 2, ScreenX375(465), ScreenX375(100), ScreenX375(100))];
    timeView.image = bgImg;
    timeView.layer.cornerRadius = ScreenX375(50);
    timeView.clipsToBounds = YES;
    [self.shadowView addSubview:timeView];
    
    UILabel *timeNote = [[UILabel alloc] initWithFrame:CGRectMake(0, ScreenX375(21), ScreenX375(100), ScreenX375(18))];
    timeNote.text = @"倒计时";
    timeNote.font = Kfont(16);
    timeNote.textAlignment = NSTextAlignmentCenter;
    timeNote.textColor = REXADECIMALCOLOR(@"#ffffff");
    [timeView addSubview:timeNote];
    
    self.timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, ScreenX375(40), ScreenX375(100), ScreenX375(40))];
    self.timeLabel.text = [NSString stringWithFormat:@"%ldS",(long)self.time];
    self.timeLabel.font = Kfont(36);
    self.timeLabel.textAlignment = NSTextAlignmentCenter;
    self.timeLabel.textColor = REXADECIMALCOLOR(@"#ffffff");
    [timeView addSubview:self.timeLabel];
    
    self.timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timerCountAction) userInfo:nil repeats:YES];
    [self.timer fire];
}

- (void)timerCountAction{
    self.time--;
    
    self.timeLabel.text = [NSString stringWithFormat:@"%ldS",(long)self.time];
    if (self.time == 0) {
        [self.timer invalidate];
        self.timer = nil;
        if (!_shareView) {
            [self showShareView];
        }else {
            self.shadowBtn.hidden = NO;
            [UIView animateWithDuration:0.3 animations:^{
                self.shareView.frame = CGRectMake(0, SCREEN_HEIGHT - ScreenX375(180), SCREEN_WIDTH, ScreenX375(180));
            }];
        }
        [self getResult];
    }
}

- (void)showShareView {
    if (!self.shareView) {
        self.shadowBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
        self.shadowBtn.backgroundColor = [UIColor colorWithWhite:0 alpha:0.3];
        [self.shadowBtn addTarget:self action:@selector(hidden) forControlEvents:UIControlEventTouchUpInside];
        self.shadowBtn.hidden = YES;
        [kKeyWindow addSubview:self.shadowBtn];
        
        self.shareView = [[ShareView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT , SCREEN_WIDTH, ScreenX375(180))];
        __weak __typeof(self) weakSelf = self;
        self.shareView.cancel = ^{
            [weakSelf hidden];
        };
        self.shareView.wxClick = ^{
            SendMessageToWXReq *sendReq = [[SendMessageToWXReq alloc] init];
            sendReq.bText = NO;
            sendReq.scene = 0;
            
            // 2.创建分享内容
            WXMediaMessage *message = [WXMediaMessage message];
            //分享标题
            message.title = @"虾拼";
            // 描述
            message.description = weakSelf.shareName;
            //分享图片,使用SDK的setThumbImage方法可压缩图片大小
            //                message.thumbData = [NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",IMAGEHEADER,self.model.pics.firstObject]]];
            [message setThumbImage:[UIImage imageNamed:@"虾拼 logo"]];
            
            //创建多媒体对象
            WXWebpageObject *webObj = [WXWebpageObject object];
            // 点击后的跳转链接
            webObj.webpageUrl = weakSelf.shareLink;
            message.mediaObject = webObj;
            sendReq.message = message;
            [WXApi sendReq:sendReq];
            [weakSelf hidden];
        };
        self.shareView.wxGroupClick = ^{
            SendMessageToWXReq *sendReq = [[SendMessageToWXReq alloc] init];
            sendReq.bText = NO;
            sendReq.scene = 1;
            
            // 2.创建分享内容
            WXMediaMessage *message = [WXMediaMessage message];
            //分享标题
            message.title = @"虾拼";
            // 描述
            message.description = weakSelf.shareName;
            //分享图片,使用SDK的setThumbImage方法可压缩图片大小
            [message setThumbImage:[UIImage imageNamed:@"虾拼 logo"]];
            
            //创建多媒体对象
            WXWebpageObject *webObj = [WXWebpageObject object];
            // 点击后的跳转链接
            webObj.webpageUrl = weakSelf.shareLink;
            message.mediaObject = webObj;
            sendReq.message = message;
            [WXApi sendReq:sendReq];
            [weakSelf hidden];
        };
        self.shareView.qqClick = ^{
            weakSelf.tencentOAuth = [[TencentOAuth alloc] initWithAppId:kQQAppKey andDelegate:weakSelf];
            
            NSString *url = weakSelf.shareLink;
            NSString *imageUrl = [NSString stringWithFormat:@"%@",IMAGEHEADER];
            
            QQApiNewsObject *share = [QQApiNewsObject objectWithURL:[NSURL URLWithString:url] title:@"虾拼" description:weakSelf.shareName previewImageURL:[NSURL URLWithString:imageUrl]];
            SendMessageToQQReq *req = [SendMessageToQQReq reqWithContent:share];
            
            //分享到qq
            [QQApiInterface sendReq:req];
            [weakSelf hidden];
        };
        self.shareView.qqGroupClick = ^{
            weakSelf.tencentOAuth = [[TencentOAuth alloc] initWithAppId:kQQAppKey andDelegate:weakSelf];
            
            NSString *url = weakSelf.shareLink;
            NSString *imageUrl = [NSString stringWithFormat:@"%@",IMAGEHEADER];
            
            QQApiNewsObject *share = [QQApiNewsObject objectWithURL:[NSURL URLWithString:url] title:@"虾拼" description:weakSelf.shareName previewImageURL:[NSURL URLWithString:imageUrl]];
            SendMessageToQQReq *req = [SendMessageToQQReq reqWithContent:share];
            
            //分享到qq
            [QQApiInterface SendReqToQZone:req];
            [weakSelf hidden];
        };
        self.shareView.wbClick = ^{
            //微博
            WBMessageObject *message = [WBMessageObject message];
            message.text = [NSString stringWithFormat:@"虾拼 %@  %@",weakSelf.shareName,weakSelf.shareLink];
            
            WBAuthorizeRequest *authRequest = [WBAuthorizeRequest request];
            authRequest.redirectURI = kWeiboAppRedirectURL;
            authRequest.scope = @"all";
            
            WBSendMessageToWeiboRequest *sharerequest = [WBSendMessageToWeiboRequest requestWithMessage:message authInfo:authRequest access_token:nil];
            [WeiboSDK sendRequest:sharerequest];
            [weakSelf hidden];
        };
        [kKeyWindow addSubview:self.shareView];
    }
    self.shadowBtn.hidden = NO;
    [UIView animateWithDuration:0.3 animations:^{
        self.shareView.frame = CGRectMake(0, SCREEN_HEIGHT - ScreenX375(180), SCREEN_WIDTH, ScreenX375(180));
    }];
}

- (void)hidden {
    [UIView animateWithDuration:0.3 animations:^{
        self.shareView.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, ScreenX375(180));
    } completion:^(BOOL finished) {
        self.shadowBtn.hidden = YES;
    }];
}

- (void)close {
    _resultView.hidden = YES;
    [kKeyWindow endEditing:YES];
    [UIView animateWithDuration:0.3 animations:^{
        self.shareView.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, ScreenX375(180));
    } completion:^(BOOL finished) {
        self.shadowBtn.hidden = YES;
    }];
}

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
    if ([text isEqualToString:@"\n"]) {
        [textView resignFirstResponder];
        return NO;
    }
    return YES;
}

- (void)dealloc {
    [self.timer invalidate];
    self.timer = nil;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end

@implementation PKDetailModel

+(JSONKeyMapper*)keyMapper
{
    return [[JSONKeyMapper alloc] initWithModelToJSONDictionary:@{
                                                                  @"Id": @"id"
                                                                  }];
}

@end
